home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Q: '\n' character
- Date: Sun, 14 Apr 1996 14:28:21 GMT
- Organization: Netcom
- Message-ID: <317109ea.316698628@nntp.ix.netcom.com>
- References: <4kj66f$k0o@ren.cei.net> <1996Apr11.192937.25676@sq.com> <829396473snz@genesis.demon.co.uk> <4kpd2g$eeb@masala.cc.uh.edu>
- NNTP-Posting-Host: ix-dc13-11.ix.netcom.com
- X-NETCOM-Date: Sun Apr 14 9:30:05 AM CDT 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- cosc19z5@Bayou.UH.EDU (Spasmo) wrote:
-
- > Lawrence Kirby (fred@genesis.demon.co.uk) wrote:
- > : In article <1996Apr11.192937.25676@sq.com> msb@sq.com "Mark Brader" writes:
- >
- > [Snip]
- >
- >
- > : >In the specific case of a string obtained from fgets(), we can be
- > : >sure that if there is a newline then it is the last character.
- > : >This leads to the alternative approach:
- > : >
- > : > ptr = strchr (buffer, '\n'); /* or strrchr() */
- > : > if (ptr) *ptr = '\0';
- >
- > Ok, I've got a question at this point. Is it really proper to say
- > if (ptr)? From what I've read, NULL wasn't supposed to be guaranteed
- > to work with true/false tests like the above, so the only safe way
- > was if (ptr != NULL). As a matter of fact, that's what Stroustrup
- > mentioned in his C++ book as a reason for using 0 instead of the NULL
- > pointer when using C++, so that true/false tests could be safely performed.
- >
- > If I'm wrong please tell me since I've been sticking with ptr != NULL
- > now for the very reason of safety. I would love to go for a good old
- > true/false test rather than a NULL comparison if in fact this is
- > valid regardless of implementation. I've learned to stay away from
- > testing code and going with the results since different implementations
- > have different behaviors at times so even if my own experience would
- > have shown the true/false approach to work I still would have avoided
- > it until I heard an official "yes it can be done, or no it can't".
-
- Read some different books.
-
- if (ptr)
- statement1
-
- executes statement1 if ptr compares equal to 0 (ISO 6.6.4), i.e., if
- ptr == 0.
-
- 0 is a null pointer constant (ISO 6.2.2.3)
-
- Michael M Rubenstein
-